package com.mjk.common.web.getway.restful.interceptor.type.imports.impl;


import com.mjk.common.base.response.BeeResponse;
import com.mjk.common.tools.excel.type.FileType;
import com.mjk.common.tools.interceptor.InterceptorChain;
import com.mjk.common.web.getway.restful.interceptor.GetWayInterceptorReq;
import com.mjk.common.web.getway.restful.interceptor.annotation.BeeGetWayInterceptor;
import com.mjk.common.web.getway.restful.interceptor.type.GetWayInterceptor;
import com.mjk.common.web.getway.restful.interceptor.type.GetWayInterceptorType;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 文件格式拦截器
 *
 * @author mjk
 */
@BeeGetWayInterceptor(value = 3, interceptorType = GetWayInterceptorType.IMPORT)
public class ImportFileTypeInterceptor implements GetWayInterceptor {
	private static final String FILETYPE = "fileType";

	@Override
	public BeeResponse interceptor(GetWayInterceptorReq request,
								   InterceptorChain<GetWayInterceptorReq, BeeResponse> next) {
		Map<String, Object> params = CollectionUtils.isEmpty(request.getParams()) ? new HashMap<>() : request.getParams();
		params.put(FILETYPE, FileType.getFileTypeByName(request.getFileName()));
		request.setParams(params);
		return next.proceed(request);
	}
}
